{extend name="common/base_page" /}

{block name="title"}盘点管理{/block}

{block name="jscssfile"}{/block}

{block name="css"}
<style type="text/css">
body{ background: #ffffff; height:100vh; }
.layui-fluid {
    padding:10px 15px;
}
.layui-tab {
    margin: 0 0;
}
.layui-tab-content{  
  padding:0px;
}
.layui-tab-content .layui-tab-item{
  height:100vh;
}
#bar_box_one{
  padding: 0px 0px 5px 0px;
  margin-bottom:0px;
}
.layui-table, .layui-table-view { margin:0; }
.layui-form-item .layui-input-inline { margin-right: 0px; }
</style>
{/block}

{block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12" style="height:100vh;padding:0;">

            <div class="layui-form-item" id="bar_box_one">
                <a class="layui-btn layui-btn-normal" href="{:url('index/store.pandian/info')}">新增盘点单</a>
                <div class="layui-input-block" style="float: right;">
                  <form class="layui-form" action="">
                      <div class="layui-inline">
                        <label class="layui-form-label">盘点时间</label>
                        <div class="layui-input-inline">
                          <input type="text" name="ipt_date" id="ipt_date" autocomplete="off" class="layui-input">
                        </div>
                      </div>
                      <div class="layui-inline">
                        <label class="layui-form-label" style="width:30px;padding: 9px 15px 9px 0;">状态</label>
                        <div class="layui-input-inline">
                          <select id="status" name="status">
                              <option value="ALL">所有</option>
                              <option value="0">未确认</option>
                              <option value="1">已确认</option>
                          </select>
                        </div>
                      </div>
                      <div class="layui-inline">
                        <div class="layui-input-inline">
                          <input type="text" name="keyword" id="keyword" maxlength="20" placeholder="单号/制单人/确认人" autocomplete="off" class="layui-input">
                        </div>
                      </div>
                      <div class="layui-inline">
                          <a class="layui-btn layui-btn-normal" onclick="_p = 1;_loadList();">搜索</a>
                      </div>
                    </form>
                </div>
            </div>
            <div class="layui-tab-content">
                  <div class="layui-tab-item layui-show">
                      <table id="LAY-app-content-comm" lay-filter="LAY-app-content-comm"></table>
                  </div>
            </div>

        </div>
    </div>
</div>
{/block}

{block name="script"}
<script src="__INDEX__/js/store/pandian.js?v={$site.version}"></script>
<script type="text/html" id="statusTpl">
  {{#  if(d.status){ }}
    <button class="layui-btn layui-btn-xs">已确认</button>
  {{#  } else { }}
    <button class="layui-btn layui-btn-primary layui-btn-xs">未确认</button>
  {{#  } }}
</script>
<script type="text/html" id="table-content-com">
  {{#  if(d.status){ }}
  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail"><i class="layui-icon layui-icon-form"></i>查看详情</a>
  {{#  } else { }}
  <a class="layui-btn layui-btn-xs" lay-event="confim"><i class="layui-icon layui-icon-ok"></i>确认</a>
  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
  {{#  } }}
</script>
<script type="text/javascript">
var _p = 1;
$(function(){
  setTimeout(function(){
      //日期范围
      laydate.render({ elem: '#ipt_date',range: true });
      _loadList();
  },50);
});
//加载数据
function _loadList()
{
      __showLoadingBox('请稍候...');
      laytable.render({
          elem: '#LAY-app-content-comm'//指定表格元素
          ,url:"{:url('index/store.pandian/index')}"
          ,method:'post'  //提交方式
          ,where:{create_time:$.trim($('#ipt_date').val()),keyword:$.trim($('#keyword').val()),status:$.trim($('#status').val()),page:_p} //post json数据
          ,page: {layout: ['count', 'prev', 'page', 'next', 'skip'],first: true,last: true}
          ,skin: 'line '  //表格风格 line （行边框风格）row （列边框风格）nob （无边框风格）
        　,even: true    //隔行换色
          ,limit: 20     //每页默认显示的数量
          ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
          ,height: 'full-100' //表格高度，layui 2.2.1 新增 , full-100 为适应最大高度或其它数值500
          ,cols: getTableConfigField()
          ,done:function(datalist,curr,page){
              __hideLoadingBox();
          }
      });

      laytable.on('tool(LAY-app-content-comm)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var _data = obj.data; //获得当前行数据
          var _event = obj.event; //获得 lay-event 对应的值
          if(_event === 'edit'){ //编辑
              goToNewPage("{:url('index/store.pandian/info')}?id=" + _data.id);
          }
          if(_event === 'detail'){ //查看详情
              goToNewPage("{:url('index/store.pandian/detail')}?id=" + _data.id);
          }
          if(_event === 'confim'){ //确认
            layer.confirm('您确认本条数据正确无误吗？', {
                title:'盘点确认',shade:[0.4,'#000000'],btn: ['确认','取消'] //按钮
            }, function(){
                layer.closeAll();
                _Index.ajax("{:url('index/store.pandian/confim')}",{id:_data.id},function(d){
                    if(d.err == 0)
                    {
                      layer.msg(d.msg, {time: 1000},function(){
                          laytable.reload('LAY-app-content-comm');
                      });
                    }else{
                      layer.msg(d.msg, {time: 2000,anim: 4});
                    }
                },'请稍候...');
            });
          }
          if(_event === 'del'){ //删除
            layer.confirm('您确定要删除本条数据吗？', {
                title:'删除',shade:[0.4,'#000000'],btn: ['确定','取消'] //按钮
            }, function(){
                layer.closeAll();
                _Index.ajax("{:url('index/store.pandian/del')}",{id:_data.id},function(d){
                    if(d.err == 0)
                    {
                      obj.del();
                      layer.msg(d.msg, {time: 1000},function(){
                          laytable.reload('LAY-app-content-comm');
                      });
                    }else{
                      layer.msg(d.msg, {time: 2000,anim: 4});
                    }
                },'请稍候...');
            });
          }
      });
}
</script>
{/block}